/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2012
 */

package com.tech15.pub.dao;

import java.util.*;

import javacommon.base.*;
import javacommon.util.*;

import cn.org.rapid_framework.util.*;
import cn.org.rapid_framework.web.util.*;
import cn.org.rapid_framework.page.*;
import cn.org.rapid_framework.page.impl.*;

import com.tech15.pub.model.*;
import com.tech15.pub.dao.*;
import com.tech15.pub.service.*;
import com.tech15.pub.vo.query.*;

/**
 * @author 胡作正 email:zuozhenghu@sina.com
 * @version 1.0
 * @since 1.0
 */


import static cn.org.rapid_framework.util.ObjectUtils.*;
import org.springframework.stereotype.Repository;

@Repository
public class PubCostDao extends BaseHibernateDao<PubCost,java.lang.String>{

	public Class getEntityClass() {
		return PubCost.class;
	}
	
	public Page findByPageRequest(PageRequest<Map> pageRequest) {
		//XsqlBuilder syntax,please see http://code.google.com/p/rapid-xsqlbuilder
		// [column]为字符串拼接, {column}为使用占位符. 以下为图方便采用sql拼接,适用性能要求不高的应用,使用占位符方式可以优化性能. 
		// [column] 为PageRequest.getFilters()中的key
		String sql = "select t from PubCost t where 1=1 "
				+ "/~ and t.nd = '[nd]' ~/"
				+ "/~ and t.lb = '[lb]' ~/"
				+ "/~ and t.ygbh = '[ygbh]' ~/"
				+ "/~ and t.ygxm = '[ygxm]' ~/"
				+ "/~ and t.cj = '[cj]' ~/"
				+ "/~ and t.bz = '[bz]' ~/"
				+ "/~ and t.dw = '[dw]' ~/"
				+ "/~ and t.ywc = '[ywc]' ~/"
				+ "/~ and t.qnkbxed = '[qnkbxed]' ~/"
				+ "/~ and t.y1 = '[y1]' ~/"
				+ "/~ and t.y2 = '[y2]' ~/"
				+ "/~ and t.y3 = '[y3]' ~/"
				+ "/~ and t.y4 = '[y4]' ~/"
				+ "/~ and t.y5 = '[y5]' ~/"
				+ "/~ and t.y6 = '[y6]' ~/"
				+ "/~ and t.y7 = '[y7]' ~/"
				+ "/~ and t.y8 = '[y8]' ~/"
				+ "/~ and t.y9 = '[y9]' ~/"
				+ "/~ and t.y10 = '[y10]' ~/"
				+ "/~ and t.y11 = '[y11]' ~/"
				+ "/~ and t.y12 = '[y12]' ~/"
				+ "/~ order by [sortColumns] ~/";
		return pageQuery(sql,pageRequest);
	}
	
	public Page findPage(PubCostQuery query) {
        //XsqlBuilder syntax,please see http://code.google.com/p/rapid-xsqlbuilder
        // [column]为字符串拼接, {column}为使用占位符. [column]为使用字符串拼接,如username='[username]',偷懒时可以使用字符串拼接 
        // [column] 为PageRequest的属性
		String sql = "select t from PubCost t where 1=1 "
			  	+ "/~ and t.nd = {nd} ~/"
			  	+ "/~ and t.lb = {lb} ~/"
			  	+ "/~ and t.ygbh = {ygbh} ~/"
			  	+ "/~ and t.ygxm = {ygxm} ~/"
			  	+ "/~ and t.cj = {cj} ~/"
			  	+ "/~ and t.bz = {bz} ~/"
			  	+ "/~ and t.dw = {dw} ~/"
			  	+ "/~ and t.ywc = {ywc} ~/"
			  	+ "/~ and t.qnkbxed = {qnkbxed} ~/"
			  	+ "/~ and t.y1 = {y1} ~/"
			  	+ "/~ and t.y2 = {y2} ~/"
			  	+ "/~ and t.y3 = {y3} ~/"
			  	+ "/~ and t.y4 = {y4} ~/"
			  	+ "/~ and t.y5 = {y5} ~/"
			  	+ "/~ and t.y6 = {y6} ~/"
			  	+ "/~ and t.y7 = {y7} ~/"
			  	+ "/~ and t.y8 = {y8} ~/"
			  	+ "/~ and t.y9 = {y9} ~/"
			  	+ "/~ and t.y10 = {y10} ~/"
			  	+ "/~ and t.y11 = {y11} ~/"
			  	+ "/~ and t.y12 = {y12} ~/"
				+ "/~ order by [sortColumns] ~/";
				
        //生成sql2的原因是为了不喜欢使用xsqlbuilder的同学，请修改生成器模板，删除本段的生成
        StringBuilder sql2 = new StringBuilder("select t from PubCost t where 1=1 ");
        if(isNotEmpty(query.getId())) {
            sql2.append(" and  t.id = :id ");
        }
        if(isNotEmpty(query.getNd())) {
            sql2.append(" and  t.nd = :nd ");
        }
        if(isNotEmpty(query.getLb())) {
            sql2.append(" and  t.lb = :lb ");
        }
        if(isNotEmpty(query.getYgbh())) {
            sql2.append(" and  t.ygbh = :ygbh ");
        }
        if(isNotEmpty(query.getYgxm())) {
            sql2.append(" and  t.ygxm = :ygxm ");
        }
        if(isNotEmpty(query.getCj())) {
            sql2.append(" and  t.cj = :cj ");
        }
        if(isNotEmpty(query.getBz())) {
            sql2.append(" and  t.bz = :bz ");
        }
        if(isNotEmpty(query.getDw())) {
            sql2.append(" and  t.dw = :dw ");
        }
        if(isNotEmpty(query.getYwc())) {
            sql2.append(" and  t.ywc = :ywc ");
        }
        if(isNotEmpty(query.getQnkbxed())) {
            sql2.append(" and  t.qnkbxed = :qnkbxed ");
        }
        if(isNotEmpty(query.getY1())) {
            sql2.append(" and  t.y1 = :y1 ");
        }
        if(isNotEmpty(query.getY2())) {
            sql2.append(" and  t.y2 = :y2 ");
        }
        if(isNotEmpty(query.getY3())) {
            sql2.append(" and  t.y3 = :y3 ");
        }
        if(isNotEmpty(query.getY4())) {
            sql2.append(" and  t.y4 = :y4 ");
        }
        if(isNotEmpty(query.getY5())) {
            sql2.append(" and  t.y5 = :y5 ");
        }
        if(isNotEmpty(query.getY6())) {
            sql2.append(" and  t.y6 = :y6 ");
        }
        if(isNotEmpty(query.getY7())) {
            sql2.append(" and  t.y7 = :y7 ");
        }
        if(isNotEmpty(query.getY8())) {
            sql2.append(" and  t.y8 = :y8 ");
        }
        if(isNotEmpty(query.getY9())) {
            sql2.append(" and  t.y9 = :y9 ");
        }
        if(isNotEmpty(query.getY10())) {
            sql2.append(" and  t.y10 = :y10 ");
        }
        if(isNotEmpty(query.getY11())) {
            sql2.append(" and  t.y11 = :y11 ");
        }
        if(isNotEmpty(query.getY12())) {
            sql2.append(" and  t.y12 = :y12 ");
        }
        if(isNotEmpty(query.getSortColumns())) {
            sql2.append(" order by :sortColumns ");
        }	
        
		return pageQuery(sql,query);
	}
	

}
